package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.TowerHistory;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/2/25
 *
 * 塔吊详情历史数据适配器
 */

public class TowerDataHistoryListAdapter extends RecyclerAdapter<TowerHistory, TowerDataHistoryListAdapter.TowerHistoryListViewHolder> {

    public TowerDataHistoryListAdapter(Context context, List<TowerHistory> dataList) {
        super(context, dataList);
    }

    @Override
    public TowerHistoryListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_tower_data_list_history, null);
        return new TowerHistoryListViewHolder(view);
    }

    @Override
    public void onBindViewHolder(TowerHistoryListViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class TowerHistoryListViewHolder extends RecyclerAdapter.BaseViewHolder<TowerHistory>{
        @BindView(R.id.create_time_tv)
        HXTextView createTimeTv;
        @BindView(R.id.tower_warning_type_tv)
        HXTextView towerWarningTypeTv;
        @BindView(R.id.tower_alarm_type_tv)
        HXTextView towerAlarmTypeTv;
        @BindView(R.id.tower_violation_type_tv)
        HXTextView towerViolationTypeTv;
        @BindView(R.id.tower_normal_type_tv)
        HXTextView towerNormalTypeTv;

        public TowerHistoryListViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(int position) {
            final TowerHistory towerHistory = dataList.get(position);
            createTimeTv.setText(towerHistory.getTime());
            if(towerHistory.getWarningStatus() == 1){//	是否预警，0否，1是
                towerWarningTypeTv.setVisibility(View.VISIBLE);
                if(towerNormalTypeTv.getVisibility() == View.VISIBLE){
                    towerNormalTypeTv.setVisibility(View.GONE);
                }
            }else {
                towerWarningTypeTv.setVisibility(View.GONE);
            }
            if(towerHistory.getAlarmStatus() == 1){//	是否报警，0否，1是
                towerAlarmTypeTv.setVisibility(View.VISIBLE);
                if(towerNormalTypeTv.getVisibility() == View.VISIBLE){
                    towerNormalTypeTv.setVisibility(View.GONE);
                }
            }else {
                towerAlarmTypeTv.setVisibility(View.GONE);
            }
            if(towerHistory.getIllegalStatus() == 1){//	是否违章，0否，1是
                towerViolationTypeTv.setVisibility(View.VISIBLE);
                if(towerNormalTypeTv.getVisibility() == View.VISIBLE){
                    towerNormalTypeTv.setVisibility(View.GONE);
                }
            }else {
                towerViolationTypeTv.setVisibility(View.GONE);
            }
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickListener.onClick(towerHistory);
                }
            });
        }
    }
}
